using AspectCoreDemo.Transaction.Host.Dtos;
using AspectCoreDemo.Transaction.Host.Models;
using AspectCoreDemo.Transaction.Host.Repositories;
using Microsoft.AspNetCore.Mvc;

namespace AspectCoreDemo.Transaction.Host.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class OrderController : ControllerBase
    {
        private readonly IOrderRepository _orderRepository;

        public OrderController(IOrderRepository orderRepository)
        {
            _orderRepository = orderRepository;
        }

        [HttpGet("Orders")]
        public async Task<List<Order>> GetOrders()
        {
            return await _orderRepository.GetAll();
        }

        [HttpPost]
        public async Task<Order> Create(CreateOrderDto input)
        {
            var order = new Order()
            {
                Name = input.Name,
                ProductId = input.ProductId,
            };
            order = await _orderRepository.Create(order);
            return order;
        }
    }
}